<template>
	<view class="auth">

		<view class="nav_bar" style="background-color: rgba(255, 255, 255, 1);">
			<uni-nav-bar color="#333" left-icon="left" title="入驻" :border='false' :fixed="true"
				background-color="transparent" @clickLeft="$native.backAction()"></uni-nav-bar>
		</view>

		<view class="nav_box"></view>

		<!--  <view class="toAuth flex_r_between" v-if="user.id">
			<image :src="$util.prefix('auth/to_store.png')" mode="aspectFill" @click="toStore">
			</image>
			<image :src="$util.prefix('auth/to_guild.png')" mode="aspectFill" @click="toGuild">
			</image>
		</view> -->

		<view class="loading">
			<HevuLoading type="loading4" :opacity="0" loadingText="正在努力加载..." text-color="#FD2A53"
				loadingIconColor="#FD2A53" />
		</view>

	</view>
</template>

<script>
	import HevuLoading from '@/components/hevu-loading/hevu-loading.vue';
	export default {
		components: {
			HevuLoading
		},
		data() {
			return {
				user: {},

				//  商家 1    公会 2    公会 3
				type: 1,

				circle_id: 0,
				

			}
		},
		methods: {
			toStore() {
				if (!this.user.auth_status) {
					return;
				}
				if (this.user.auth_status == 2) {
					uni.navigateTo({
						url: '/pages/auth/storeType'
					})
				} else {
					return this.$util.msg('请先完成实人认证(我的 - 认证)');
				}

			},

			toGuild() {
				if (!this.user.auth_status) {
					return;
				}
				if (this.user.auth_status == 2) {
					uni.navigateTo({
						url: '/pages/auth/guildAuth'
					})
				} else {
					return this.$util.msg('请先完成实人认证(我的 - 认证)');
				}
			},

			getUser() {
				this.$get('user/info').then(res => {
					this.user = res.data;
					uni.setStorageSync('user', res.data);
					// 2024.11.10 商家入驻 编辑商家资料后 store_id 就变成了 0
					// D：当前版本只能这样做

					if (this.type == 3) {
						// 员工
						this.$util.toUrl('/pages/newstore/newstore', 'redirectTo')
					} else if (this.type == 1) {
						// 商家
						this.$post('/store/getStoreAuthInfo', {}, false).then(res => {
							var status = res.data.status || 0;
							if (status == 2) {
								this.$util.toUrl('/pages/newstore/newstore', 'redirectTo')
							} else {
								this.$util.toUrl(`/pages/auth/storeAuth?circle_id=${this.circle_id}`,
									'redirectTo')
							}
							return;
						})

					} else if (this.type == 2) {
						// 公会

						this.$get('/guild/getGuildData', {
							user_id: this.user.id,
							auth: 3,
							circle_id: this.circle_id
						}, false, (res => {
							this.$util.toUrl(`/pages/auth/guildAuth?circle_id=${this.circle_id}`,
								'redirectTo');
							return;
						})).then(res => {
							if(res.data.guild_info.status == 2){
								this.$util.toUrl(`/pages/guild/guild?circle_id=${this.circle_id}`,
									'redirectTo');
								return;
							}else {
								this.$util.toUrl(`/pages/auth/guildAuth?circle_id=${this.circle_id}`,
									'redirectTo');
								return;
							}
						})
						// if (this.user.guild_id || this.user.sign_guild_id) {

						// } else {

						// }
					}


					// 员工中心  增加判断  是否进行了资格认证
					// if(this.user.sign_store_id > 0){
					// 	this.$util.toUrl('/pages/provider/provider', 'redirectTo')
					// }

				})
			}
		},

		onLoad(option) {
			// type 1 商家 2 公会
			this.type = option.type;
			this.circle_id = option.circle_id || 0;
			if (option.token) {
				uni.setStorageSync('token', option.token);
				uni.setStorageSync('cid', option.cid);
				uni.setStorageSync('terminal', option.terminal);
			} else {
				this.$util.msg('登录失效，请重新登录');
			}
			this.getUser();
		}
	}
</script>

<style lang="less" scoped>
	.auth {
		padding: 176rpx 46rpx 0;
	}

	.toAuth {
		image {
			width: 300rpx;
			height: 368rpx;
		}
	}
</style>